<template>
  <div class="equipment_template table_container wrap_table">
    <el-table
      :data="templateList"
      border
      ref="deviceTemplate"
      max-height="440"
      class="table_dialog">
      <el-table-column
        prop="number"
        align="center"
        label="序号"
        width="55">
      </el-table-column>
      <el-table-column
        prop="name"
        min-width="300"
        label="检查内容">
      </el-table-column>
      <el-table-column
        prop="type"
        :resizable="false"
        min-width="200"
        align="center"
        label="检查记录">
        <template slot-scope="scope">
          <div v-if="scope.row.type === '布尔值'">
            <template v-if="!readonly">
              <el-radio v-model="scope.row.value" label="ID_BT_True">是</el-radio>
              <el-radio v-model="scope.row.value" label="ID_BT_False">否</el-radio>
            </template>
            <span v-else>{{
              scope.row.value === 'ID_BT_True' ? '是':
              scope.row.value === 'ID_BT_False'? '否': ''
              }}</span>
          </div>
          <div class="tem_textarea" v-else-if="scope.row.type === '文本值'">
            <el-input type="textarea"
                      v-if="!readonly"
                      placeholder="请输入"
                      rows="1"
                      resize="none"
                      v-model="scope.row.value"></el-input>
            <span v-else>{{scope.row.value}}</span>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'EquipmentTemplate',
  props: {
    // 是否只读
    readonly: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    templateList: {
      handler(now, old) {
        if (this.isEdit === false) {
          this.isEdit = true
        }
      },
      deep: true
    }
  },
  data() {
    return {
      isEdit: null, // 是否修改过
      templateList: [], // 设备参数模板
    }
  },
  mounted() {
    this.$refs.deviceTemplate.doLayout()
  },
  methods: {
    openDialog(templateList) {
      this.isEdit = null
      this.templateList = templateList
      this.$nextTick(() => {
        this.isEdit = false
      })
    }
  }
}
</script>

<style scoped lang="less">
  .equipment_template{
    .tem_textarea {
      padding-top: 3px;
      .el-textarea{
        vertical-align: top;
      }
    }
  }
</style>
